import { ref, watch, reactive, getCurrentInstance } from 'vue'
import {Search, Plus, Upload} from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
import request from '@/utils/request'
import buttonAction from './component/buttonAction'
import $button from '@/button'
const proxy = getCurrentInstance();

export const operationItem = reactive({
    defaultSearch: false,//默认搜索按钮
    defaultRefresh: false,//默认重置按钮
    customTableHeader: false,//
    SearchItem: [
        {
            code: 'sale',
            name: '商家名称/编号',
            type: 'input',
        },
        {
            code: 'saleRoot',
            name: '销售名称/编号',
            type: 'select',
            options: []
        },
        {
            code: ["registerDateStart", "registerDateEnd"],//
            startName: "注册日期", //默认是开始时间 type为 daterange生效
            rangeName: "", //默认是至 type为 daterange生效
            endName: "注册日期", //默认是结束时间 type为 daterange生效
            valueFormat: "", //默认是YYYY-MM-DD
            placeholder: "请选择日期",//默认是请选择日期type为date生效
            type: "daterange",//daterange或date
        },
        {
            code: ["dateStart", "dateEnd"],//
            startName: "开始日期", //默认是开始时间 type为 daterange生效
            rangeName: "", //默认是至 type为 daterange生效
            endName: "结束日期", //默认是结束时间 type为 daterange生效
            valueFormat: "", //默认是YYYY-MM-DD
            placeholder: "请选择日期",//默认是请选择日期type为date生效
            type: "daterange",//daterange或date
        }
    ],
    menuArray: [
        {
            show: true,
            type: 'primary',
            text: '查询',
            icon: Search,
            handle: () => {
            }
        },
        {
            show: true,
            type: 'primary',
            text: '导出',
            hasPermi: [$button.coursemanagementexport|| null],
            icon: Upload,
            handle: () => {
            }
        },
    ]
})

export const tableItem = reactive({
    select: false,
    index: !true,
    tree: true,
    expandAll: true,
    align: 'center',
    column: [
        {
            label: '商家名称',
            prop: 'sale',
            align: 'center',
        },
        {
            label: '手机号',
            prop: 'mobile',
            align: 'center',
        },
        {
            label: '注册时间',
            prop: 'registerTime',
            align: 'center',
        },
        {
            label: '成交单数',
            prop: 'dealAmount',
            align: 'center',
            sortable: 'custom'
        },
        {
            label: '累计消费',
            prop: 'dealPrice',
            align: 'center',
            sortable: 'custom',
            htmlContent: row => {
                return `<span>${row.dealPrice || 0}</span> `
            },
        },
        {
            label: '累计佣金',
            prop: 'commissionPrice',
            align: 'center',
            sortable: 'custom',
            htmlContent: row => {
                return `<span>${row.commissionPrice || 0}</span> `
            },
        },
        {
            label: '累计提现',
            prop: 'withdrawalPrice',
            align: 'center',
            sortable: 'custom',
            htmlContent: row => {
                return `<span>${row.withdrawalPrice || 0}</span> `
            },
        },
        {
            label: '所属销售',
            prop: 'saleRoot',
            align: 'center',
        },
        {
            label: '操作',
            prop: 'action',
            align: 'center',
            component: buttonAction
        }
    ],
    pageInfo: {
        request: {
            'sale': '',
            'saleRoot': '',
            "registerDateStart": "",
            "registerDateEnd": "",
            "dateStart": "",
            "dateEnd": "",
            'pageDomain': {
                'pageNum': '1',//分页页面数
                'pageSize': '10',//分页页面数据大小
                'orderByColumn': '',//搜索参数
                'isAsc': '',//搜索参数
                'reasonable': ''//搜索参数
            }
        },
        url: '/sale/management/paging',//分页路由，不传的话需要传入自定义的分页函数paging 传入时定义的分页函数paging会失效 /sale/management/paging
        method: 'POST',//分页请求方法，不传默认为POST
        // 分页函数paging
        paging: function () {
        }
    },
    // 分页数据 自定义分页函数paging时需要把值赋给tableData
    tableData: {
        total: '',//分页总计
        // 分页数据
        data: []
    },
    // 操作栏按钮
    btnArray: [
        {
            label: '禁用',
            type: 'danger',//类别 摈弃了text
            labelEn: 'status',
            show: true,
            hasPermi: [$button.coursemanagementdisable|| null],
            plain: true,//镂空按钮  优先文字按钮
            text: true,//文字按钮
            // 按钮方法
            handle: function (row) {
            }
        },
        {
            label: '启用',
            type: 'primary',//类别 摈弃了text
            labelEn: 'status',
            show: true,
            hasPermi: [$button.coursemanagementdisable|| null],
            plain: true,//镂空按钮  优先文字按钮
            text: true,//文字按钮
            // 按钮方法
            handle: function (row) {
            }
        },
    ],
    moreBtnArrayText: '',
    moreBtnArray: [],
    // 选择框触发
    selectChange: function (row) {
    },
}
)

// 启用禁用
export function saleDisableApi(dataRequest) {
    return request({
        url: '/sale/management/disable',
        method: 'PUT',
        data: dataRequest
    })
}
// 销售列表
export function saleListApi(dataRequest) {
    return request({
        url: '/sale/list',
        method: 'POST',
        data: dataRequest
    })
}



